package com.khiker.sort;

public class DubboSelection implements Sort {
	@Override
	public int[] sort(int[] array) {
		int min, max, l = array.length / 2;
		for (int i = 0; i < l; i++) {
			int length = array.length - i - 1;
			if (array[i] > array[length]) {
				min = length;
				max = i;
			} else {
				min = i;
				max = length;
			}
			for (int j = i + 1; j < length; j++) {
				if (array[min] > array[j]) {
					min = j;
				}
				if (array[max] < array[j]) {
					max = j;
				}
			}
			swap(array, i, min);
			swap(array, length, i == max ? min : max);
		}
		return array;
	}


	public static void main(String[] args) {
		DubboSelection selection = new DubboSelection();
		selection.checkMulti(100);
//		selection.sort(new int[]{1877684625, -116954928, 1025933892});
	}
}
